package com.xyz.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.apache.dubbo.config.annotation.DubboReference;
import org.springframework.stereotype.Service;

/**
 * @author 肖咉卓
 */
@Service("userService") //放到容器中
public class UserServiceImpl {
    /**
     * 要去注册中心拿到服务
     * @DubboReference  //引用 Pom坐标，要定义路径相同的接口名
     */

    /**
     * 设置直连方式
     * @DubboReference(version = "1.0",url = "127.0.0.1:20880",group = "provider_server")
     */

    /**
     * random :随机 默认
     * roundrobin :循环
     */
    @DubboReference(loadbalance = "roundrobin")
    TicketService ticketService;

    /**
     * 当调用远程错误时，调用本地hello方法
     * @return
     */
    @HystrixCommand(fallbackMethod = "hello")
    public String buyTicket(){
        String ticket=ticketService.getTicket();
        System.out.println("在注册中心拿到=>"+ticket);
        return ticket;
    }
    public String hello(){

        return "调用hello，去服务器取值错误";
    }
}
